package com.shengwei.truck.driver.view.ui.common;

import android.os.Bundle;
import android.view.View;
import androidx.lifecycle.ViewModel;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.shengwei.truck.driver.R;
import com.shengwei.truck.driver.databinding.ScalePhotoBinding;
import com.shengwei.truck.driver.view.ui.BaseActivity;

import uk.co.senab.photoview.PhotoViewAttacher;

public class ScalePhotoActivity extends BaseActivity<ViewModel, ScalePhotoBinding> {
    String mPhotoUrl;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //得到上一页传递过来的图片地址
        getLastIntent();
        //加载图片显示
        showPhoto();
    }

    private void getLastIntent() {
        Bundle b = this.getIntent().getExtras();
        if(b != null) {
            mPhotoUrl = b.getString("photoUrl");
        }
    }

    /**
     * 显示图片，可缩放
     */
    private void showPhoto() {
        PhotoViewAttacher attacher = new PhotoViewAttacher(mDataBinding.imvPhoto);
        attacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float x, float y) {
                ScalePhotoActivity.this.finish();
            }
        });
        RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.DATA); //只缓存的原图
        Glide.with(this)
                .load(mPhotoUrl)
                .apply(options)
                .into(mDataBinding.imvPhoto);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.scale_photo;
    }
}
